#include "SequenceFunctionFactory.h"

#include "sequencerunner.h"
#include "SequenceModel.h"
#include "QtTimerService.h"
#include "sequencerunner.h"
#include "SequenceGuiFactory.h"
#include "ActionListController.h"

#include "QAbstractItemModel"

SequenceFunctionFactory::SequenceFunctionFactory(QObject *parent) :
   QObject(parent)
{
}


SequenceModel * SequenceFunctionFactory::buildModel()
{
   QList<SequenceItem *> * sequenceList = new QList<SequenceItem *>();
   return new SequenceModel( *sequenceList, this);
}

SequenceRunner *SequenceFunctionFactory::buildEngine( QWidget *container, SequenceModel *sequenceModel,
                                                      QAbstractItemModel *mediaModel,
                                                      QAbstractItemModel *lightModel)
{
   SequenceRunner * runner = new SequenceRunner( *sequenceModel, new QtTimerService(this), this);

   SequenceGuiFactory * guiFactory = new SequenceGuiFactory( runner, sequenceModel, container);

   ActionListController *actionController = new ActionListController( *sequenceModel, this);
   guiFactory->build( actionController, runner, mediaModel, lightModel);

   connect( actionController, SIGNAL(activeRowChanged(int)), runner, SLOT(selectIndex(int)) );
   connect( runner, SIGNAL(activateRow(int)), actionController, SLOT(activateRequest(int)) );

   return runner;
}
